<template>
    <div id="app">
        <!-- v-if="isRouterAlive" -->
        <!-- <router-view></router-view> -->
        <keep-alive v-if="isLoggedIn">
            <router-view v-if="$route.meta.keepAlive"></router-view>
        </keep-alive>
        <router-view v-if="!$route.meta.keepAlive||!isLoggedIn"></router-view>
    </div>
</template>
<style>
@import './assets/css/main.css';
@import './assets/css/color-dark.css';
/*深色主题*/
/*@import "./assets/css/theme-green/color-green.css";   浅绿色主题*/
</style>
<script>
export default {
    name: 'app',
    provide() {
        return {
            reload: this.reload
        };
    },
    data() {
        return {
            isLoggedIn: false,
            isRouterAlive: true
        };
    },
    watch: {
        $route(to, from) {
            // if the route changes...
            let token = localStorage.getItem('token') || '';
            if (token) {
                // firebase returns null if user logged out
                this.isLoggedIn = true;
            } else {
                this.isLoggedIn = false;
            }
        }
    },
    methods: {
        reload() {
            this.isRouterAlive = false;
            this.$nextTick(() => {
                this.isRouterAlive = true;
            });
        }
    },
    mounted() {
        // window.onbeforeunload = function (e) {
        //     const storage = window.localStorage
        //     storage.clear()
        // }
    }
};
</script>
